package day03;

import javax.swing.tree.TreeNode;
import java.util.*;

/**
 * @author jhj
 * @date 2022/5/11 18:57
 */
public class TestTreeSearch {
    public static void main(String[] args) {
        System.out.println(LinkedList.class);
        System.out.println(TreeNode.class);

        MyTreeNode node = new MyTreeNode();

    }
    public List<Integer> preorderTraversal(MyTreeNode root) {
        List<Integer> ret = new ArrayList<>();
        Stack<MyTreeNode> stack = new Stack<>();
        stack.push(root);
        while (!stack.isEmpty()) {
            MyTreeNode node = stack.pop();
            if (node == null) continue;
            ret.add(node.val);
            stack.push(node.right);  // 先右后左，保证左子树先遍历
            stack.push(node.left);
        }
        return ret;
    }

}
class MyTreeNode implements TreeNode{
    public int val;
    public MyTreeNode left;
    public MyTreeNode right;
    @Override
    public TreeNode getChildAt(int childIndex) {
        return null;
    }

    @Override
    public int getChildCount() {
        return 0;
    }

    @Override
    public TreeNode getParent() {
        return null;
    }

    @Override
    public int getIndex(TreeNode node) {
        return 0;
    }

    @Override
    public boolean getAllowsChildren() {
        return false;
    }

    @Override
    public boolean isLeaf() {
        return false;
    }

    @Override
    public Enumeration<? extends TreeNode> children() {
        return null;
    }
}
